package sac.xsd.comm;


import javax.microedition.lcdui.Alert;

import sac.mainmid.MainMID;
import sac.screen.LoginScreen;


public class CptRResponse {
	private static byte RESULT_STATE = -1;

	private static final byte RESULT_EMPTY = -1;

	public static final byte RESULT_SUCCESS = 0;

	public static final byte RESULT_NO_REGISTED = 1;

	public static final byte RESULT_INVALIDATE = 2;

	public static final byte RESULT_DATABASE_ERROR = 3;

	public static final byte RESULT_SYSTEM_ERROR = 4;

	public static final byte RESULT_PASSWORD_ERROR = 5;

	public static final byte RESULT_FAILED_PHONE_NUMBER_EXISTED = 6;

	public static final byte RESULT_FAILED_ORIGINAL_NUMBER_NOT_EXISTED = 7;

	public static final byte RESULT_FAILED_PHONE_NUMBER_TOO_SHORT = 8;

	public static final byte RESULT_FAILED_PHONE_NUMBER_NOT_EXISTED = 9;

	public static final byte RESULT_FAILED_OVER_MAXIMUM_COUNT = 10;

	public static final byte RESULT_FAILED_START_WITH_NAT = 11;

	public static final byte RESULT_FAILED_START_WITH_SUBTRACTION_SIGN = 12;

	public static final byte RESULT_FAILED_PHONE_NUMBER_TOO_LONG = 13;

	public static final byte RESULT_FAILED_PERIOD_CONFLICTED = 14;
	
	public static final byte RESULT_FAILED_OVER_MAX_COUNT=15;
	
	public static final byte RESULT_FAILED_INDEX_NOT_EXISTED=16;

	public static final String SUCCESS = "success";

	public static final String NO_REGISTED = "failed_not_registed";

	public static final String INVALIDATE = "invalidate_parameters";

	public static final String DATABASE_ERROR = "database_error";

	public static final String SYSTEM_ERROR = "system_error";

	public static final String PASSWORD_ERROR = "failed_password_error";

	public static final String FAILED_PHONE_NUMBER_EXISTED = "failed_phone_number_existed";

	public static final String FAILED_ORIGINAL_NUMBER_NOT_EXISTED = "failed_original_number_not_existed";

	public static final String FAILED_PHONE_NUMBER_TOO_SHORT = "failed_phone_number_too_short";

	public static final String FAILED_PHONE_NUMBER_NOT_EXISTED = "failed_phone_number_not_existed";

	public static final String FAILED_OVER_MAXIMUM_COUNT = "failed_over_maximum_count";

	public static final String FAILED_START_WITH_NAT = "failed_start_with_nat";

	public static final String FAILED_START_WITH_SUBTRACTION_SIGN = "failed_start_with_subtraction_sign";

	public static final String FAILED_PHONE_NUMBER_TOO_LONG = "failed_phone_number_too_long";

	public static final String FAILED_PERIOD_CONFLICTED = "failed_period_conflict";
	
	public static final String FAILED_OVER_MAX_COUNT="failed_over_max_count";
	
	public static final String FAILED_INDEX_NOT_EXISTED="failed_index_not_existed";

	
	/**
	 * check the response result
	 * @param result Return null if check success, other return the Alert.
	 * @return
	 */
	public static Alert checkResponseResult(String result) {
		RESULT_STATE = RESULT_EMPTY;
		Alert aa = null;
		if (result.equals(SUCCESS)) {
			RESULT_STATE = RESULT_SUCCESS;
			return null;
		}
		
		if (result.equals(NO_REGISTED)) {
			RESULT_STATE = RESULT_NO_REGISTED;
			aa = new Alert(MainMID.getFirstResource("error"), MainMID.getFirstResource("error_1"), null, null);
			aa.setTimeout(Alert.FOREVER);
		}
		else if (result.equals(INVALIDATE)) {
			RESULT_STATE = RESULT_INVALIDATE;
			aa = new Alert(MainMID.getFirstResource("error"), MainMID.getFirstResource("error_2"), null, null);
			aa.setTimeout(Alert.FOREVER);
		}
		else if (result.equals(DATABASE_ERROR)) {
			RESULT_STATE = RESULT_DATABASE_ERROR;
			aa = new Alert(MainMID.getFirstResource("error"), MainMID.getFirstResource("error_3"), null, null);
			aa.setTimeout(Alert.FOREVER);
		}
		else if (result.equals(SYSTEM_ERROR)) {
			RESULT_STATE = RESULT_SYSTEM_ERROR;
			aa = new Alert(MainMID.getFirstResource("error"), MainMID.getFirstResource("error_4"), null, null);
			aa.setTimeout(Alert.FOREVER);
		}
		else if (result.equals(PASSWORD_ERROR)) {
			RESULT_STATE = RESULT_PASSWORD_ERROR;
			aa = new Alert(MainMID.getFirstResource("error"), LoginScreen.getLoginMsisdn()
					+ MainMID.getFirstResource("error_5"), null, null);
			aa.setTimeout(Alert.FOREVER);
		}
		else if (result.equals(FAILED_PHONE_NUMBER_EXISTED)) {
			RESULT_STATE = RESULT_FAILED_PHONE_NUMBER_EXISTED;
			aa = new Alert(MainMID.getFirstResource("error"), MainMID.getFirstResource("error_6")
					+ MainMID.getListPhone() + MainMID.getFirstResource("error_7"), null, null);
			aa.setTimeout(Alert.FOREVER);
		}
		else if (result.equals(FAILED_ORIGINAL_NUMBER_NOT_EXISTED)) {
			RESULT_STATE = RESULT_FAILED_ORIGINAL_NUMBER_NOT_EXISTED;
			aa = new Alert(MainMID.getFirstResource("error"), MainMID.getFirstResource("error_8")
					+ MainMID.getListPhone() + MainMID.getFirstResource("error_9"), null, null);
			aa.setTimeout(Alert.FOREVER);
		}
		else if (result.equals(FAILED_PHONE_NUMBER_TOO_SHORT)) {
			RESULT_STATE = RESULT_FAILED_PHONE_NUMBER_TOO_SHORT;
			aa = new Alert(MainMID.getFirstResource("error"), MainMID.getFirstResource("error_10"), null, null);
			aa.setTimeout(Alert.FOREVER);
		}
		else if (result.equals(FAILED_PHONE_NUMBER_NOT_EXISTED)) {
			RESULT_STATE = RESULT_FAILED_PHONE_NUMBER_NOT_EXISTED;
			aa = new Alert(MainMID.getFirstResource("error"), MainMID.getFirstResource("error_11"), null, null);
			aa.setTimeout(Alert.FOREVER);
		}
		else if (result.equals(FAILED_OVER_MAXIMUM_COUNT)) {
			RESULT_STATE = RESULT_FAILED_OVER_MAXIMUM_COUNT;
			aa = new Alert(MainMID.getFirstResource("error"), MainMID.getFirstResource("error_12"), null, null);
			aa.setTimeout(Alert.FOREVER);
		}
		else if (result.equals(FAILED_START_WITH_NAT)) {
			RESULT_STATE = RESULT_FAILED_START_WITH_NAT;
			aa = new Alert(MainMID.getFirstResource("error"), MainMID.getFirstResource("error_13"), null, null);
			aa.setTimeout(Alert.FOREVER);
		}
		else if (result.equals(FAILED_START_WITH_SUBTRACTION_SIGN)) {
			RESULT_STATE = RESULT_FAILED_START_WITH_SUBTRACTION_SIGN;
			aa = new Alert(MainMID.getFirstResource("error"), MainMID.getFirstResource("error_14"), null, null);
			aa.setTimeout(Alert.FOREVER);
		}
		else if (result.equals(FAILED_PHONE_NUMBER_TOO_LONG)) {
			RESULT_STATE = RESULT_FAILED_PHONE_NUMBER_TOO_LONG;
			aa = new Alert(MainMID.getFirstResource("error"),MainMID.getFirstResource("error_15"), null, null);
			aa.setTimeout(Alert.FOREVER);
		}
		else if (result.equals(FAILED_PERIOD_CONFLICTED)) {
			RESULT_STATE = RESULT_FAILED_PERIOD_CONFLICTED;
			aa = new Alert(MainMID.getFirstResource("error"), MainMID.getFirstResource("error_16"), null, null);
			aa.setTimeout(Alert.FOREVER);
		}
		else if (result.equals(FAILED_OVER_MAX_COUNT)) {
			RESULT_STATE = RESULT_FAILED_OVER_MAX_COUNT;
			aa = new Alert(MainMID.getFirstResource("error"), MainMID.getFirstResource("error_17"), null, null);
			aa.setTimeout(Alert.FOREVER);
		}
		else if (result.equals(FAILED_INDEX_NOT_EXISTED)) {
			RESULT_STATE = RESULT_FAILED_INDEX_NOT_EXISTED;
			aa = new Alert(MainMID.getFirstResource("error"), MainMID.getFirstResource("error_18"), null, null);
			aa.setTimeout(Alert.FOREVER);
		}
		
		return aa;
	}

	public static byte getResultState() {
		return RESULT_STATE;
	}
}
